loadStatFile("stat_descriptions.txt")

local itemClassMap = {
	[4] = "Amulet",
	[5] = "Ring",
	[6] = "Claw",
	[7] = "Dagger",
	[8] = "Wand",
	[9] = "One Handed Sword",
	[10] = "Thrusting One Handed Sword",
	[11] = "One Handed Axe",
	[12] = "One Handed Mace",
	[13] = "Bow",
	[14] = "Staff",
	[15] = "Two Handed Sword",
	[16] = "Two Handed Axe",
	[17] = "Two Handed Mace",
	[20] = "Quiver",
	[21] = "Belt",
	[22] = "Gloves",
	[23] = "Boots",
	[24] = "Body Armour",
	[25] = "Helmet",
	[26] = "Shield",
	[32] = "Sceptre",
}
local out = io.open("../Data/3_0/ModMaster.lua", "w")
out:write('-- This file is automatically generated, do not edit!\n')
out:write('-- Item data (c) Grinding Gear Games\n\nreturn {\n')
for _, craftKey in ipairs(CraftingBenchOptions.IsDisabled(false)) do
	local craft = CraftingBenchOptions[craftKey]
	if craft.ModsKey and itemClassMap[craft.ItemClassesKeys[1]] then
		local mod = Mods[craft.ModsKey]
		out:write('\t{ ')
		if mod.GenerationType == 1 then
			out:write('type = "Prefix", ')
		elseif mod.GenerationType == 2 then
			out:write('type = "Suffix", ')
		end
		out:write('affix = "', mod.Name, '", ')
		local stats, orders = describeMod(mod)
		out:write('"', table.concat(stats, '", "'), '", ')
		out:write('statOrder = { ', table.concat(orders, ', '), ' }, ')
		out:write('level = ', mod.Level, ', group = "', mod.CorrectGroup, '", ')
		local master = NPCMaster[craft.NPCMasterKey]
		local npc = NPCs[NPCs.Id(master.NPCsKey)[1]]
		out:write('master = "', npc.ShortName, '", masterLevel = ', craft.MasterLevel, ', ')
		out:write('types = { ')
		for _, itemClassesKey in ipairs(craft.ItemClassesKeys) do
			out:write('["', itemClassMap[itemClassesKey], '"] = true, ')
		end
		out:write('}, ')
		out:write('},\n')
	end
end
out:write('}')
out:close()

print("Master mods exported.")